package com.dfrz.service.impl;

import com.dfrz.entity.History;
import com.dfrz.mapper.HistoryMapper;
import com.dfrz.service.HistoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author 29877
 */
@Service
public class HistoryServiceImpl implements HistoryService {
    @Resource
    private HistoryMapper historyMapper;
    @Override
    public List<History> getHistory(Integer uid) {
        List<History> lists=historyMapper.getHistory(uid);
        List<History> history=new ArrayList<>();
        Iterator<History> iterator=lists.iterator();
        while (iterator.hasNext()){
            History col=iterator.next();
            History temp=historyMapper.getDetailTypeAndImg(col.getVideoId());
            col.setDetailType(temp.getDetailType());
            col.setVideoImg(temp.getVideoImg());

            history.add(col);
        }
        return history;
    }

    @Override
    public void addhistory(Integer uid, Integer vid) {
        historyMapper.deleteHistorybyUidAndVid(uid, vid);
        String time= LocalDateTime.now().toString();
        historyMapper.addhistory(uid,vid,time);
    }
    @Override
    public void deletehistory(Integer hid) {
        historyMapper.deletehistorybyid(hid);
    }

    @Override
    public void deleteall(Integer uid) {
            historyMapper.deletehistorybyuid(uid);
    }

}
